<style lang="less" scoped>

</style>

<template>
  <div :id="chartId" />
</template>

<script>
import * as echarts from 'echarts'
export default {
  // eslint-disable-next-line vue/require-prop-types
  props: ['chartId', 'legendTitle', 'timeLine', 'chartData', 'leftY', 'rightY'],
  data() {
    return {}
  },
  mounted() {
    this.getChart()
  },
  methods: {
    getChart() {
      let myChart = echarts.init(document.getElementById(this.chartId))
      // myChart.clear()
      window.addEventListener('resize', myChart.resize)
      if (this.timeLine.length > 0) {
        let option = {
          color: ['#59BCFB', '#FFD300'],
          grid: {
            top: '20%',
            right: '10%',
            left: '10%',
            bottom: '15%'
          },
          legend: {
            textStyle: {
              color: '#fff'
            },
            data: this.legendTitle
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'cross',
              crossStyle: {
                color: '#999'
              }
            }
          },
          xAxis: [
            {
              type: 'category',
              axisLine: {
                lineStyle: {
                  color: '#59BCFB33'
                }
              },
              splitLine: {
                show: false
              },
              axisTick: {
                show: false
              },
              axisLabel: {
                color: 'fff'
              },
              data: this.timeLine,
              axisPointer: {
                type: 'shadow'
              }
            }
          ],
          yAxis: [
            {
              show: this.leftY,
              type: 'value',
              name: '（' + this.leftY + '）',
              nameTextStyle: {
                color: '#fff'
              },
              axisLabel: {
                color: 'fff'
              },
              axisLine: {
                lineStyle: {
                  color: '#59BCFB33'
                }
              },
              splitLine: {
                show: false
              },
              axisTick: {
                show: false
              }
            },
            {
              show: this.rightY,
              type: 'value',
              name: '（' + this.rightY + '）',
              nameTextStyle: {
                color: '#fff'
              },
              axisLabel: {
                color: 'fff'
              },
              axisLine: {
                lineStyle: {
                  color: '#59BCFB33'
                }
              },
              splitLine: {
                show: false
              },
              axisTick: {
                show: false
              }
            }
          ],
          series: this.chartData
        }
        myChart.setOption(option)
      }
    }
  }
}
</script>
